<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        td {
            padding: 2px 0px;
            text-align: left;
            border: 1px solid #999;
        }
    </style>
    <link href="/resources/css/table.css?r=3" rel="stylesheet">
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <link  href="/resources/viewer/viewer.css" rel="stylesheet">
    <script src="/resources/viewer/viewer.js"></script>
</head>
<body>

<div>
    <table style="width:100%;">
        <tr>
            <td colspan="9">
                <button onclick="back()" class="btn btn-primary" type="button" style="float: right;margin-right: 20px;">返回</button>
            </td>


        </tr>
        <tr>
            <td class="name" colspan="2">
                监控设备：
            </td>
            <td>
                <select name="deviceId" id="deviceId" class="form-control form-data">
                </select>
                <input type="hidden" name="id" class="form-data">
            </td>
            <td class="name" title="生产（经营）企业所在县、市、区">
                生产（经营）企业所在县、市、区：
            </td>
            <td>
                <input type="text" name="companyAdd" id="companyAdd"
                       class="form-control form-data ">
            </td>
            <td class="name" title="流向地（县、市、区）">
                流向地（县、市、区）：
            </td>
            <td>
                <input type="text" name="lxd" id="lxd"
                       class="form-control form-data ">
            </td>
            <td class="name">
                用途：
            </td>
            <td>
                <input type="text" name="use" id="use"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">
                购买单位：
            </td>
            <td>
                <select name="buyCompanyId" id="buyCompanyId" class="form-control form-data">
                </select>
            </td>
            <td class="name">
                运输公司：
            </td>
            <td>
                <select name="transportCompanyId" id="transportCompanyId" onchange="selectTransportCompanyId('', '')" class="form-control form-data">
                </select>
            </td>
            <td class="name">
                运输车辆牌号：
            </td>
            <td>
                <input type="text" name="transportCarInfo"
                       class="form-control form-data ">
            </td>
            <td class="name">
                联系方式：
            </td>
            <td>
                <input type="text" id="buyCompanyTelephone" name="buyCompanyTelephone"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">
                购买单位经办人：
            </td>
            <td>
                <input type="text" name="buyerName" id="buyerName"
                       class="form-control form-data ">
            </td>
            <td class="name">
                性别：
            </td>
            <td>
                <select name="buyerSex" id="buyerSex" class="form-control form-data"
                        style="width:150px;float: left" >
                    <option value="man">男</option>
                    <option value="woman">女</option>
                </select>
            </td>
            <td class="name">
                身份证号：
            </td>
            <td>
                <input type="text" id="buyerCard" name="buyerCard"
                       class="form-control form-data ">
            </td>
            <td class="name">
                联系方式：
            </td>
            <td>
                <input type="text" id="buyerTelephone" name="buyerTelephone"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">
                驾驶员姓名：
            </td>
            <td>
                <select name="practitionerDriverId" id="practitionerDriverId" onchange="selectPractitionerDriver()" class="form-control form-data">
                </select>
            </td>
            <td class="name">
                性别：
            </td>
            <td>
                <!--<select name="driverSex" id="driverSex" class="form-control form-data" disabled
                        style="width:150px;float: left" >
                    <option value="man">男</option>
                    <option value="woman">女</option>
                </select>-->

                <input type="text" name="driverSex" id="driverSex" disabled
                       class="form-control form-data ">
            </td>
            <td class="name">
                身份证号：
            </td>
            <td>
                <input type="text" id="driverCard" name="driverCard"   disabled
                       class="form-control form-data ">
            </td>
            <td class="name">
                联系方式：
            </td>
            <td>
                <input type="text" id="driverTelephone" name="driverTelephone" disabled
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">
                押运员姓名：
            </td>
            <td>
                <select name="practitionerSupercargoId" id="practitionerSupercargoId" onchange="selectPractitionerSupercargo()" class="form-control form-data">
                </select>
            </td>
            <td class="name">
                性别：
            </td>
            <td>
              <!--  <select name="supercargoSex" id="supercargoSex"  style="width:150px;float: left"
                        class="form-control form-data">
                    <option value="man">男</option>
                    <option value="woman">女</option>
                </select>-->

                <input type="text" name="supercargoSex" id="supercargoSex" disabled
                       class="form-control form-data ">
            </td>
            <td class="name">
                身份证号：
            </td>
            <td>
                <input type="text" id="supercargoCard" name="supercargoCard" disabled
                       class="form-control form-data ">
            </td>
            <td class="name">
                联系方式：
            </td>
            <td>
                <input type="text" id="supercargoTelephone" name="supercargoTelephone" disabled
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">
                开始时间：
            </td>
            <td>
                <input type="text" name="timeBegin" id="timeBegin"
                       class="form-control form-data "  onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
            </td>
            <td class="name">
                结束时间：
            </td>
            <td>
                <input type="text" name="timeEnd" id="timeEnd"
                       class="form-control form-data "  onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
            </td>
            <td class="name">
                数量：
            </td>
            <td colspan="3">
              <!--  <input type="text" id="amount" name="amount"
                       class="form-control form-data" style="width:80% !important;">
                <input type="text"  name="unit" readonly
                       class="form-control form-data col-md-7 col-xs-12" style="width:20% !important;">-->
                <input type="text" id="amount" name="amount"
                       class="form-control form-data col-md-7 col-xs-12" style="width:80% !important;">
                <input type="text"  name="unit" readonly
                       class="form-control form-data col-md-7 col-xs-12" style="width:20% !important;">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">
                描述：
            </td>
            <td colspan="7">
                <textarea class="form-control form-data" name="desc" rows="3" placeholder=""></textarea>
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">
                公司备注：
            </td>
            <td colspan="7">
                <textarea class="form-control form-data" name="companyRemark" rows="3" placeholder=""></textarea>
            </td>
        </tr>
        <tr>
            <td class="name" colspan="3">
                运输车辆图片
                <div>
                    <input type="file" id="car_input" name="file" onchange="uploadFile('car')" value="Upload your resume"
                           style="opacity: 0;width: 0px;display: none">
                    <button class="btn btn-primary" onclick="$('#car_input').click();" >
                        上传文件
                    </button>
                </div>

            </td>
            <td class="name" colspan="3">
                驾驶员图片
                <div>
                    <input type="file" id="driverImages_input" name="file" onchange="uploadFile('driverImages')" value="Upload your resume"
                           style="opacity: 0;width: 0px;display: none">
                    <button class="btn btn-primary" onclick="$('#driverImages_input').click();" >
                        上传文件
                    </button>
                </div>


            </td>
            <td class="name" colspan="3">
                押运员图片
                <div>
                    <input type="file" id="supercargoImages_input" name="file" onchange="uploadFile('supercargoImages')" value="Upload your resume"
                           style="opacity: 0;width: 0px;display: none">
                    <button class="btn btn-primary" onclick="$('#supercargoImages_input').click();" >
                        上传文件
                    </button>
                </div>

            </td>
        </tr>
        <tr>

            <td colspan="3" style="text-align: center">
                <div  id="car_div" style="margin-top: 20px;" >
                </div>
            </td>
            <td colspan="3" style="text-align: center">
                <div  id="driverImages_div" style="margin-top: 20px;" >
                </div>
            </td>
            <td colspan="3" style="text-align: center">
                <div id="supercargoImages_div" style="margin-top: 20px;">
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="9">
                <button onclick="save()" class="btn btn-success">提交</button>
                <!--<button onclick="back()" class="btn btn-primary" type="button">返回</button>-->
            </td>


        </tr>

    </table>
</div>


<!--<div class="row">-->
    <!--<div class="col-md-12 col-sm-12 col-xs-12">-->
        <!--<div class="x_panel">-->
            <!--<div class="x_title">-->
                <!--<h2>销售记录维护 <small></small></h2>-->
                <!--<ul class="nav navbar-right panel_toolbox">-->
                    <!--<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>-->
                    <!--</li>-->
                    <!--<li class="dropdown">-->
                        <!--<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>-->
                        <!--<ul class="dropdown-menu" role="menu">-->
                            <!--<li><a href="#">Settings 1</a>-->
                            <!--</li>-->
                            <!--<li><a href="#">Settings 2</a>-->
                            <!--</li>-->
                        <!--</ul>-->
                    <!--</li>-->
                    <!--<li><a class="close-link"><i class="fa fa-close"></i></a>-->
                    <!--</li>-->
                <!--</ul>-->
                <!--<div class="clearfix"></div>-->
            <!--</div>-->
            <!--<div class="x_content">-->
                <!--<br>-->
                <!--<div id="demo-form2"  class="form-horizontal form-label-left" >-->
                    <!--<input type="hidden" name="id" class="form-data" >-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12" for="deviceId">监控设备-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<select name="deviceId" id="deviceId" class="form-control form-data">-->
                            <!--</select>-->
                        <!--</div>-->
                    <!--</div>-->
                   <!--&lt;!&ndash; <div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">销售记录名称-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<input type="text" id="name" name="name"-->
                                   <!--class="form-control form-data col-md-7 col-xs-12" >-->
                        <!--</div>-->
                    <!--</div>&ndash;&gt;-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12" for="deviceId">购买商-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<select name="buyCompanyId" id="buyCompanyId" class="form-control form-data">-->
                            <!--</select>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12" for="deviceId">运输公司-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<select name="transportCompanyId" id="transportCompanyId" class="form-control form-data">-->
                            <!--</select>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">运输车辆牌号-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--&lt;!&ndash;<textarea class="form-control form-data" name="transportCarInfo" rows="3" placeholder=""></textarea>&ndash;&gt;-->
                            <!--<input type="text" name="transportCarInfo" class="form-control form-data">-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">运输车图片-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<div>-->
                                <!--<input type="file" id="car_input" name="file" onchange="uploadFile('car')" value="Upload your resume"-->
                                       <!--style="opacity: 0;width: 0px;display: none">-->
                                <!--<button class="btn btn-primary" onclick="$('#car_input').click();" >-->
                                    <!--上传文件-->
                                <!--</button>-->
                            <!--</div>-->
                            <!--<div  id="car_div" style="margin-top: 20px;" >-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--&lt;!&ndash;<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">运输人员信息-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<textarea class="form-control form-data" name="transportPeople" rows="3" placeholder=""></textarea>-->
                        <!--</div>-->
                    <!--</div>&ndash;&gt;-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">驾驶员信息-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<div>-->
                                <!--<div style="border: 1px solid #ccc;padding: 4px">-->
                                    <!--<div>-->
                                        <!--<san style="width:100px;display: block;float: left">姓名：</san>-->
                                        <!--<input type="text" name="driverName" class="form-control form-data"-->
                                               <!--style="width:150px;float: left" >-->
                                        <!--<san  style="width:100px;display: block;float: left">性别：</san>-->
                                        <!--<select name="driverSex" id="driverSex" class="form-control form-data"-->
                                                <!--style="width:150px;float: left" >-->
                                            <!--<option value="man">男</option>-->
                                            <!--<option value="woman">女</option>-->
                                        <!--</select>-->
                                        <!--<div style="clear: both"></div>-->
                                    <!--</div>-->

                                    <!--<div style="margin-top:20px">-->
                                        <!--<san style="width:100px;display: block;float: left">身份证号：</san>-->
                                        <!--<input type="text" name="driverCard"  style="width:150px;float: left"-->
                                               <!--class="form-control form-data">-->

                                        <!--<san style="width:100px;display: block;float: left">联系方式：</san>-->
                                        <!--<input type="text" name="driverTelephone"  style="width:150px;float: left"-->
                                               <!--class="form-control form-data">-->
                                        <!--<div style="clear: both"></div>-->
                                    <!--</div>-->


                                <!--</div>-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">押运员信息-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<div style="margin-top: 15px">-->
                                <!--<div style="border: 1px solid #ccc;padding: 4px">-->
                                    <!--<div>-->

                                        <!--<san style="width:100px;display: block;float: left">  姓名：</san>-->
                                        <!--<input type="text" name="supercargoName" style="width:150px;float: left"-->
                                                  <!--class="form-control form-data">-->


                                        <!--<san style="width:100px;display: block;float: left">   性别：</san>-->
                                        <!--<select name="supercargoSex" id="supercargoSex"  style="width:150px;float: left"-->
                                                <!--class="form-control form-data">-->
                                            <!--<option value="man">男</option>-->
                                            <!--<option value="woman">女</option>-->
                                        <!--</select>-->
                                        <!--<div style="clear: both"></div>-->
                                    <!--</div>-->

                                    <!--<div style="margin-top:20px">-->
                                        <!--<san style="width:100px;display: block;float: left"> 身份证号：</san>-->

                                            <!--<input type="text" name="supercargoCard"  style="width:150px;float: left"-->
                                                    <!--class="form-control form-data">-->

                                        <!--<san style="width:100px;display: block;float: left">  联系方式：</san>-->
                                            <!--<input type="text" name="supercargoTelephone"  style="width:150px;float: left"-->
                                                    <!--class="form-control form-data">-->
                                        <!--<div style="clear: both"></div>-->
                                    <!--</div>-->

                                <!--</div>-->
                                <!--<div style="clear: both"></div>-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">运输人图片资料-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<div>-->
                                <!--<input type="file" id="people_input" name="file" onchange="uploadFile('people')" value="Upload your resume"-->
                                       <!--style="opacity: 0;width: 0px;display: none">-->
                                <!--<button class="btn btn-primary" onclick="$('#people_input').click();" >-->
                                    <!--上传文件-->
                                <!--</button>-->
                            <!--</div>-->
                            <!--<div  id="people_div" style="margin-top: 20px;" >-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12" for="timeBegin">开始时间-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<input type="text" id="timeBegin" name="timeBegin" class="form-control form-data"-->
                                   <!--onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12" for="timeEnd">结束时间-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<input type="text" id="timeEnd" name="timeEnd" class="form-control form-data"-->
                                   <!--onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">-->
                        <!--</div>-->
                    <!--</div>-->

                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12" for="amount">数量-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<input type="text" id="amount" name="amount"-->
                                   <!--class="form-control form-data col-md-7 col-xs-12" style="width:80% !important;">-->
                            <!--<input type="text"  name="unit" readonly-->
                                   <!--class="form-control form-data col-md-7 col-xs-12" style="width:20% !important;">-->
                        <!--</div>-->
                    <!--</div>-->


                    <!--<div class="form-group">-->
                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">描述-->
                        <!--</label>-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                            <!--<textarea class="form-control form-data" name="desc" rows="3" placeholder=""></textarea>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="ln_solid"></div>-->
                    <!--<div class="form-group">-->
                        <!--<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">-->
                            <!--<button onclick="save()" class="btn btn-success">提交</button>-->
                            <!--<button onclick="back()" class="btn btn-primary" type="button">返回</button>-->
                        <!--</div>-->
                    <!--</div>-->

                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
    <!--</div>-->
<!--</div>-->
</body>
<script type="text/javascript">
    $(function () {
        buildSelect("/trans/device/listAll.do","#deviceId","id","name",{});
        buildSelect("/trans/buyCompany/listAll.do","#buyCompanyId","id","name",{});
        buildSelect("/trans/transportCompany/listAll.do","#transportCompanyId","id","name",{});
        var device =   $("#deviceId").children('option:selected').attr("b-data");
        $("input[name='unit']").val(JSON.parse(device).product.unit);
        $("#deviceId").change(function () {
            var device = $(this).children('option:selected').attr("b-data");
            $("input[name='unit']").val(JSON.parse(device).product.unit);
        });
        initData();
    });

    function selectTransportCompanyId(practitionerDriverId, practitionerSupercargoId) {
        var transportCompanyId = $("#transportCompanyId").val();
        $.ajax({
            url:"/trans/practitioner/listByCompanyId.do",
            data:{'transportCompanyId':transportCompanyId},
            type:'post',
            dataType:'json',
            success:function(data){
                if(data.success){
                    var list = data.data;
                    var driverHtml = "";
                    var supercargoHtml = "";
                    for(var i=0; i<list.length; i++) {
                         var practitioner = list[i];
                        if(practitioner.driver == 'valid') {

                            if(practitionerDriverId!='' && practitionerDriverId==practitioner.id){
                                driverHtml = driverHtml + "<option selected value='"+practitioner.id+"' name='"+practitioner.name+"' sex='"+practitioner.sex+"' idCard='"+practitioner.idCard+"' telephone='"+practitioner.telephone+"'>"+practitioner.name+"</option>"
                            } else {
                                driverHtml = driverHtml + "<option value='"+practitioner.id+"' name='"+practitioner.name+"' sex='"+practitioner.sex+"' idCard='"+practitioner.idCard+"' telephone='"+practitioner.telephone+"'>"+practitioner.name+"</option>"
                            }
                        }
                        if(practitioner.supercargo == 'valid') {
                            if(practitionerSupercargoId != '' && practitionerSupercargoId == practitioner.id) {
                                supercargoHtml = supercargoHtml + "<option selected value='"+practitioner.id+"' name='"+practitioner.name+"' sex='"+practitioner.sex+"' idCard='"+practitioner.idCard+"' telephone='"+practitioner.telephone+"'>"+practitioner.name+"</option>"
                            } else {
                                supercargoHtml = supercargoHtml + "<option value='"+practitioner.id+"' name='"+practitioner.name+"' sex='"+practitioner.sex+"' idCard='"+practitioner.idCard+"' telephone='"+practitioner.telephone+"'>"+practitioner.name+"</option>"
                            }
                        }
                    }
                    $("#practitionerDriverId").html(driverHtml);
                    $("#practitionerSupercargoId").html(supercargoHtml);
                    selectPractitionerDriver();
                    selectPractitionerSupercargo();
                }
            }
        });
    }

    function selectPractitionerDriver() {
        var driverSex = $("#practitionerDriverId").find("option:selected").attr("sex");
        var driverCard = $("#practitionerDriverId").find("option:selected").attr("idCard");
        var driverTelephone = $("#practitionerDriverId").find("option:selected").attr("telephone");
        if(driverSex == 'man') {
            driverSex = "男";
        } else {
            driverSex = "女";
        }
        $("#driverSex").val(driverSex);
        $("#driverCard").val(driverCard);
        $("#driverTelephone").val(driverTelephone);
    }

    function selectPractitionerSupercargo() {
        var supercargoSex = $("#practitionerSupercargoId").find("option:selected").attr("sex");
        var supercargoCard = $("#practitionerSupercargoId").find("option:selected").attr("idCard");
        var supercargoTelephone = $("#practitionerSupercargoId").find("option:selected").attr("telephone");
        if(supercargoSex == 'man') {
            supercargoSex = "男";
        } else {
            supercargoSex = "女";
        }
        $("#supercargoSex").val(supercargoSex);
        $("#supercargoCard").val(supercargoCard);
        $("#supercargoTelephone").val(supercargoTelephone);
    }


    function initData(){
        var data = getData();
        if(null2empty(data["id"]) !==""){
            var id = data.id;
            $("input[name='id']").val(id);
            $.ajax({
                url:"/trans/saleOrder/find.do",
                data:{'id':id},
                type:'post',
                dataType:'json',
                success:function(data){
                    console.log(data);
                    $("#imgDiv img").attr("src",data.data.image);
                    addFileInfoToTable(data.data.carImageList,'car');
                    addFileInfoToTable(data.data.peopleImageList,'people');
                    if(data.success){
                        initPageDate(data.data, '.form-data');
                        var practitionerDriverId = data.data.practitionerDriverId;
                        var practitionerSupercargoId = data.data.practitionerSupercargoId;
                        selectTransportCompanyId(practitionerDriverId, practitionerSupercargoId);
                    }
                }
            });
            $("#account").attr('readonly','readonly');
        }

    }

    function save() {
        var params = getPageDataByClass("form-data");
      /*  if (strIsNull(params['name'])) {
            alert("请输入销售记录名称");
            return;
        }*/
        if (strIsNull(params['buyCompanyId'])) {
            alert("请选择采购商");
            return;
        }
        if (strIsNull(params['transportCompanyId'])) {
            alert("请选择运输公司");
            return;
        }
        if (strIsNull(params['timeBegin'])) {
            alert("请输入开始时间");
            return;
        }
        if (strIsNull(params['timeEnd'])) {
            alert("请输入开始时间");
            return;
        }
        if (strIsNull(params['amount'])) {
            alert("请输入销售数量");
            return;
        }
        params.carImage = "";
        $("input[name='car_id']").each(function(index,files){
            if(files == "") {
                params.carImage = $(this).val();
            } else {
                params.carImage = params.carImage + "," + $(this).val();
            }
        });
        params.peopleImage = "";
        $("input[name='people_id']").each(function(index,files){
            if(files == "") {
                params.peopleImage = $(this).val();
            } else {
                params.peopleImage = params.peopleImage + "," + $(this).val();
            }
        });
        params.driverImages = "";
        $("input[name='driverImages_id']").each(function(index,files){
            if(files == "") {
                params.driverImages = $(this).val();
            } else {
                params.driverImages = params.driverImages + "," + $(this).val();
            }
        });
        params.supercargoImages = "";
        $("input[name='supercargoImages_id']").each(function(index,files){
            if(files == "") {
                params.supercargoImages = $(this).val();
            } else {
                params.supercargoImages = params.supercargoImages + "," + $(this).val();
            }
        });
        $.ajax({
            url: "/trans/saleOrder/save.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    var localData = getData();
                    goto("sale_order_list.html",{"process":localData.process});
                } else {
                    alert(data.msg);
                }
            }
        });
    }

    function uploadFile(fileType) {
        $.ajaxFileUpload({
            url: "/file/uploadFile.do?_t=" + new Date().getTime(),            //需要链接到服务器地址
            secureuri: false,//是否启用安全提交，默认为false
            fileElementId: fileType+'_input',                        //文件选择框的id属性
            dataType: 'text',                                     //服务器返回的格式，可以是json, xml
            success: function (data, status) {//服务器成功响应处理函数
                var rpeObj = $.parseJSON(data);
                var fileInfoList = rpeObj.data;
                addFileInfoToTable(fileInfoList,fileType);

            }
        });
    }
    function addFileInfoToTable(fileInfoList,fileType){
        $(fileInfoList).each(function(index,file){
            var fileHtml = "<div  style='border-radius: 2px; width:48%;height:178px;float: left; border: 2px #ffffff solid;'>"+
                "<div style='height:130px;overflow:hidden;'><img class='image' style='height:130px;width:168px;' src='"+getFileShowUrl(file.path)+"'></div>"+

                "<div align='center' style='margin-top: 7px'>"+
                "<div align='center' style='word-wrap:break-word;display: none'><input type='hidden' name='"+fileType+"_id' value='"+file.id+"'>"+file.name+"</div>"+


                "<button  style='margin-left: 20px;' name='delete' extendData='"+file.id+"'class='btn btn-primary'>删除</button><div>"
            "</div>";
            $(fileHtml).appendTo($("#"+fileType+"_div"));

        });
        $('.image').viewer();
        $("button[name='delete']").unbind('click');
        $("button[name='delete']").click(function(){
            var id = $(this).attr("extendData");
            $.ajax({
                type: "POST",
                url: "/file/delete.do?_t=" + new Date().getTime(),
                data: "fileId=" + id,

                success: function (result) {
                    alert("删除成功");
                },

                error: function (XMLHttpRequest, textStatus, thrownError) {
                    /* alert("系统异常");*/
                }
            });
            $(this).parent().parent().remove();
        });
    }
    //获取要展示的图片
    function getFileShowUrl(url){
        var extStart=url.lastIndexOf(".");
        var ext=url.substring(extStart,url.length).toUpperCase();
        if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
            return "/resources/images/timg.jpg";
        }else{
            return url;
        }
    }
    function back() {
        var localData = getData();
        goto("sale_order_list.html",{"process":localData.process});
    }
</script>
</html>